import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;


public class SaveTheUniverse {

	public static void main(String[] args) {
		try {
			Output output = new Output("A-large-practice");
			BufferedReader br = new BufferedReader(new InputStreamReader(""
					.getClass().getResourceAsStream("/A-large-practice.in")));
			int testCaseNumber = Integer.valueOf(br.readLine());
			for (int i = 0; i < testCaseNumber; i++) {
				int switchCount = getSwitchCount(br);
				System.out.println("Case #" + (i + 1) + ": " + switchCount);
				output.addCase(switchCount + "");
			}
			output.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static int getSwitchCount(BufferedReader br) throws IOException {
		int engineNumber = Integer.valueOf(br.readLine());
		List<String> engines = new ArrayList<String>();
		for(int j = 0; j < engineNumber; j++) {
			engines.add(br.readLine());
		}
		List<String> canUseEngines = new ArrayList<String>(engines);
		int searchNumber = Integer.valueOf(br.readLine());
		int switchCount = 0;
		for(int j = 0; j < searchNumber; j++) {
			String search = br.readLine();
			if(canUseEngines.contains(search)) {
				canUseEngines.remove(search);
			}
			if(canUseEngines.size() == 0) {
				switchCount++;
				canUseEngines = new ArrayList<String>(engines);
				canUseEngines.remove(search);
			}
		}
		return switchCount;
	}

	
}
